﻿namespace jzgl.Windows
{
    using jzgl.Controller;
    using jzgl.Model;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class CustFromInfo : Form
    {
        private Button btn_QueDing;
        private Button btn_QuXiao;
        private Button btn_ShanChu;
        private Button btn_TianJia;
        private Button btn_XiuGai;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private IContainer components = null;
        private DataGridView dataGridView1;
        private CustFrom from = new CustFrom();
        private CustFromDB fromDB = new CustFromDB();
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private GroupBox groupBox3;
        private Label label1;
        private Panel panel1;
        private int t = 0;
        private DataTable table = null;
        private TextBox textBox1;

        public CustFromInfo()
        {
            this.InitializeComponent();
            this.Data_bind();
            this.groupBox2.Visible = true;
            this.groupBox3.Visible = false;
        }

        private void btn_QueDing_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.textBox1.Text.Trim().Equals(""))
                {
                    MessageBox.Show("来源不能为空！");
                }
                else
                {
                    this.from._CustFromName = this.textBox1.Text.Trim();
                    if ((this.t == 1) && (this.fromDB.Add_CustFrom(this.from) != 0))
                    {
                        MessageBox.Show("已添加！");
                        this.t = 0;
                    }
                    if (this.t == 2)
                    {
                        this.from._CustFromId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
                        if (this.fromDB.Update_CustFrom(this.from) != 0)
                        {
                            MessageBox.Show("修改成功！");
                            this.t = 0;
                        }
                    }
                    this.groupBox2.Visible = true;
                    this.groupBox3.Visible = false;
                    this.Data_bind();
                    this.dataGridView1.Enabled = true;
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_QuXiao_Click(object sender, EventArgs e)
        {
            try
            {
                this.groupBox3.Visible = false;
                this.groupBox2.Visible = true;
                this.textBox1.Text = "";
                this.dataGridView1.Enabled = true;
            }
            catch (Exception)
            {
            }
        }

        private void btn_ShanChu_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim().Equals("") || (this.dataGridView1.Rows.Count == 0))
                {
                    MessageBox.Show("请选择要删除的数据行！");
                }
                else if (MessageBox.Show("确定要删除吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.from._CustFromId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim());
                    if (this.fromDB.Delete_CustFrom(this.from) != 0)
                    {
                        MessageBox.Show("已删除！");
                        this.Data_bind();
                    }
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_ShuaXin_Click(object sender, EventArgs e)
        {
            try
            {
                this.dataGridView1.Rows.Clear();
                this.Data_bind();
                this.textBox1.Text = "";
                this.dataGridView1.Enabled = true;
            }
            catch (Exception)
            {
            }
        }

        private void btn_TianJia_Click(object sender, EventArgs e)
        {
            try
            {
                this.t = 1;
                this.groupBox2.Visible = false;
                this.groupBox3.Visible = true;
                this.textBox1.Text = "";
                this.dataGridView1.Enabled = false;
            }
            catch (Exception)
            {
            }
        }

        private void btn_XiuGai_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.Rows.Count == 0)
                {
                    MessageBox.Show("没有数据修改！");
                }
                else
                {
                    this.t = 2;
                    this.groupBox2.Visible = false;
                    this.groupBox3.Visible = true;
                    this.dataGridView1.Enabled = true;
                }
            }
            catch (Exception)
            {
            }
        }

        public void Data_bind()
        {
            try
            {
                this.dataGridView1.Rows.Clear();
                this.table = this.fromDB.Show_CustFrom();
                if (this.table != null)
                {
                    for (int i = 0; i < this.table.Rows.Count; i++)
                    {
                        object[] values = new object[] { this.table.Rows[i][0].ToString(), this.table.Rows[i][1].ToString() };
                        this.dataGridView1.Rows.Add(values);
                    }
                }
                this.textBox1.Text = "";
            }
            catch (Exception)
            {
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.textBox1.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
            }
            catch (Exception)
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.panel1 = new Panel();
            this.groupBox3 = new GroupBox();
            this.btn_QuXiao = new Button();
            this.btn_QueDing = new Button();
            this.textBox1 = new TextBox();
            this.label1 = new Label();
            this.groupBox2 = new GroupBox();
            this.btn_ShanChu = new Button();
            this.btn_XiuGai = new Button();
            this.btn_TianJia = new Button();
            this.groupBox1 = new GroupBox();
            this.dataGridView1 = new DataGridView();
            this.Column1 = new DataGridViewTextBoxColumn();
            this.Column2 = new DataGridViewTextBoxColumn();
            this.panel1.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            base.SuspendLayout();
            this.panel1.Controls.Add(this.groupBox3);
            this.panel1.Controls.Add(this.groupBox2);
            this.panel1.Controls.Add(this.groupBox1);
            this.panel1.Location = new Point(0, 4);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x1cb, 0x1d0);
            this.panel1.TabIndex = 0;
            this.groupBox3.Controls.Add(this.btn_QuXiao);
            this.groupBox3.Controls.Add(this.btn_QueDing);
            this.groupBox3.Controls.Add(this.textBox1);
            this.groupBox3.Controls.Add(this.label1);
            this.groupBox3.Location = new Point(3, 390);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new Size(450, 0x41);
            this.groupBox3.TabIndex = 2;
            this.groupBox3.TabStop = false;
            this.btn_QuXiao.Location = new Point(0x17a, 0x18);
            this.btn_QuXiao.Name = "btn_QuXiao";
            this.btn_QuXiao.Size = new Size(0x39, 0x17);
            this.btn_QuXiao.TabIndex = 3;
            this.btn_QuXiao.Text = "取消";
            this.btn_QuXiao.UseVisualStyleBackColor = true;
            this.btn_QuXiao.Click += new EventHandler(this.btn_QuXiao_Click);
            this.btn_QueDing.Location = new Point(0x13b, 0x18);
            this.btn_QueDing.Name = "btn_QueDing";
            this.btn_QueDing.Size = new Size(0x39, 0x17);
            this.btn_QueDing.TabIndex = 2;
            this.btn_QueDing.Text = "确定";
            this.btn_QueDing.UseVisualStyleBackColor = true;
            this.btn_QueDing.Click += new EventHandler(this.btn_QueDing_Click);
            this.textBox1.Location = new Point(0x31, 0x18);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new Size(0xf1, 0x15);
            this.textBox1.TabIndex = 1;
            this.label1.AutoSize = true;
            this.label1.Location = new Point(8, 0x1b);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x29, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "来源：";
            this.groupBox2.Controls.Add(this.btn_ShanChu);
            this.groupBox2.Controls.Add(this.btn_XiuGai);
            this.groupBox2.Controls.Add(this.btn_TianJia);
            this.groupBox2.Location = new Point(3, 390);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x1bf, 0x41);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.btn_ShanChu.Location = new Point(270, 0x15);
            this.btn_ShanChu.Name = "btn_ShanChu";
            this.btn_ShanChu.Size = new Size(0x4e, 0x17);
            this.btn_ShanChu.TabIndex = 2;
            this.btn_ShanChu.Text = "删除";
            this.btn_ShanChu.UseVisualStyleBackColor = true;
            this.btn_ShanChu.Click += new EventHandler(this.btn_ShanChu_Click);
            this.btn_XiuGai.Location = new Point(0xb9, 0x15);
            this.btn_XiuGai.Name = "btn_XiuGai";
            this.btn_XiuGai.Size = new Size(0x4f, 0x17);
            this.btn_XiuGai.TabIndex = 1;
            this.btn_XiuGai.Text = "修改";
            this.btn_XiuGai.UseVisualStyleBackColor = true;
            this.btn_XiuGai.Click += new EventHandler(this.btn_XiuGai_Click);
            this.btn_TianJia.Location = new Point(0x69, 0x15);
            this.btn_TianJia.Name = "btn_TianJia";
            this.btn_TianJia.Size = new Size(0x4a, 0x17);
            this.btn_TianJia.TabIndex = 0;
            this.btn_TianJia.Text = "添加";
            this.btn_TianJia.UseVisualStyleBackColor = true;
            this.btn_TianJia.Click += new EventHandler(this.btn_TianJia_Click);
            this.groupBox1.Controls.Add(this.dataGridView1);
            this.groupBox1.Location = new Point(3, 3);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(450, 0x17d);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "客户来源管理";
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.BackgroundColor = SystemColors.ControlLightLight;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2 });
            this.dataGridView1.Location = new Point(4, 0x15);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowHeadersWidth = 30;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.Size = new Size(0x1bb, 350);
            this.dataGridView1.TabIndex = 0;
            this.dataGridView1.CellClick += new DataGridViewCellEventHandler(this.dataGridView1_CellClick);
            this.Column1.HeaderText = "编号";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Visible = false;
            this.Column2.HeaderText = "客户来源";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 410;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(990, 780);
            base.Controls.Add(this.panel1);
            base.FormBorderStyle = FormBorderStyle.None;
            base.MaximizeBox = false;
            base.Name = "CustFromInfo";
            this.Text = "客户来源信息";
            this.panel1.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            ((ISupportInitialize) this.dataGridView1).EndInit();
            base.ResumeLayout(false);
        }
    }
}

